package com.glsc.ngateway.platform.controller.softLegal;

import com.glsc.ngateway.common.api.platform.dto.user.PlatformUserDto;
import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.platform.aspect.UserCache;
import com.glsc.ngateway.platform.domain.softLegal.SoftUpdate;
import com.glsc.ngateway.platform.service.softLegal.SoftUpdateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/softUpdate")
@Api(value = "软件升级", tags = {"软件升级"})
public class SoftUpdateController {

    @Autowired
    private SoftUpdateService softUpdateService;
    @Autowired
    private UserCache userCache;
    @Autowired
    private HttpServletRequest request;

    /**
     * 查询
     * @param params
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/search")
    @ApiOperation(value = "查询", notes = "查询")
    public PlatformResponse<Object> search(@RequestBody Object params) {
        Object result = softUpdateService.search(params);
        return PlatformResponse.successData(result);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/addOrUpdate")
    @ApiOperation(value = "修改 软件升级", notes = "修改 软件升级")
    public PlatformResponse<Void> addOrUpdate(@RequestBody SoftUpdate softUpdate) {
        PlatformUserDto user = userCache.get(request);
        String account = user.getUsername();
        softUpdateService.addOrUpdate(softUpdate,account);
        return PlatformResponse.successMsg("处理成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "/delete")
    @ApiOperation(value = "删除 软件升级", notes = "删除 软件升级")
    public PlatformResponse<Void> delete(@RequestBody SoftUpdate softUpdate) {
        PlatformUserDto user = userCache.get(request);
        String account = user.getUsername();
        softUpdateService.delete(softUpdate,account);
        return PlatformResponse.successMsg("删除成功");
    }

//    @RequestMapping(method = RequestMethod.POST, value = "/deleteList")
//    @ApiOperation(value = "批量删除 软件升级", notes = "批量删除 软件升级")
//    public PlatformResponse<Void> deleteListCpuDetail(@RequestBody List<String> codes) {
//        PlatformUserDto user = userCache.get(request);
//        String account = user.getUsername();
//        softUpdateService.deleteByCodeList(codes,account);
//        return PlatformResponse.successMsg("删除成功");
//    }
}
